import java.io.*;
import java.util.Arrays;
import java.util.Scanner;

/*
 ID: ning yusui
 LANG: JAVA
 TASK: agrinet
 */

public class agrinet {
    Scanner in;
    PrintWriter out;
    public static final int SIZE = 76;
    private int n;
    private int[][] dijMat;


    public agrinet() throws IOException {
        in = new Scanner(new File(this.getClass().getName() + ".in"));
        out = new PrintWriter(new BufferedWriter(new FileWriter(this.getClass().getName() +
                ".out")));
    }

    private void work() {
        input();
        int lowCost[] = Arrays.copyOf(dijMat[0], n);
        int ans=0;
        for(int i=1; i< n; i++){
            int minPoint = findMinCost(lowCost);
            ans+=lowCost[minPoint];
            lowCost[minPoint]=0;
            updateLowCost(lowCost, minPoint);
        }
        out.println(ans);
        out.flush();
        out.close();
    }

    private void updateLowCost(int[] lowCost, int minPoint) {
        for(int j=0; j< n; j++){
           if(dijMat[minPoint][j]<lowCost[j]){
               lowCost[j]= dijMat[minPoint][j];
           }
        }
    }

    private int findMinCost(int[] lowCost) {
        int minCost=Integer.MAX_VALUE;
        int minPoint=-1;
        for(int j=0; j< n; j++){
            if(lowCost[j]>0 && minCost> lowCost[j]){
                minCost=lowCost[j];
                minPoint=j;
            }
        }
        return minPoint;
    }

    private void input() {
        n = in.nextInt();
        dijMat = new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                dijMat[i][j] = in.nextInt();
            }
        }
    }


    public static void main(String[] args) throws IOException {
        new agrinet().work();
    }

}
